﻿using Ivory;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Ivory.GUI;
using Ivory.Libs;
using X13.Player;
using X13.Mapping;
using X13.Libs;
using X13;

namespace Sweeper
{
    using XGlobals = X13.Globals;
    

    public abstract class RenderTestBase : GameScreen
    {        
        //Fields
        private Texture2D _Background;
        private GUI _GUI;
        private AxisIndicator _AxisIndicator;

        //Construct
        public RenderTestBase(Game game)
            : base(game)
        {

        }

        //Methods 
        public override void RenderGame(SpriteBatch batch, GameTime time)
        {
            _AxisIndicator.Draw(ObjectHolder.GameCamera, time);
            RenderTest(batch, time);
        }
        public override void RenderUI(SpriteBatch batch, GameTime time)
        {
            batch.Begin();
            _GUI.DrawGUI(batch, time);
            batch.End();
        }

        public override void UpdateGame(GameTime time, InputControl input)
        {
            ObjectHolder.GameCamera.UpdateCamera(input, time);
            SelectionEngine.SolveSelection(Game, input);
            UpdateTest(time, input);
        }
        public override void UpdateUI(GameTime time, InputControl input)
        {
            _GUI.UpdateGUI(input, time);
        }

        public override bool PreloadAssets()
        {
            this.LoadingScreen = new LoadScreen(Game, Resources.FontLocations["Default"], Color.White, Color.Black);
            return true;
        }
        public override bool LoadData()
        {
            _Background = Load<Texture2D>("graphics/menubackground");

            _GUI = new GUI();

            TextButton mainMenu = new TextButton(Game, Resources.Fonts["Default"], "Main Menu", new Vector2(0, 0));
            mainMenu.ID = "MainMenuReturn";
            mainMenu.EnableShadowing = true;
            mainMenu.ButtonColor = Color.Red;
            mainMenu.ButtonHoverColor = Color.Red;
            mainMenu.LeftClicked += (s, e) => { Manager.SwitchToMainMenu(); };
            _GUI.AddComponent(mainMenu);

            _AxisIndicator = new AxisIndicator(Game, false, 3);
            _AxisIndicator.Setup();

            ObjectHolder.GameCamera = new RenderTestCamera(Game);
            LoadTest();

            return true;
        }

        public abstract void RenderTest(SpriteBatch batch, GameTime time);
        public abstract void UpdateTest(GameTime time, InputControl input);
        public abstract void LoadTest();
    }
}
